package slerp;

import java.io.Serializable;
import java.util.ArrayList;

/**
 * Class which contains all of the chunks in the map.
 * The chunks in turn contains all of the members (drawables etc).
 * @author Klas
 */
class GameMap implements Serializable {

    //Container containing chunks
    private ArrayList<Chunk> chunks = new ArrayList<Chunk>();
    
    public GameMap() {
    }

    /**
     * Add a member to a chunk, also with a specific position in the chunk.
     * This is useful if you want to replace an existing member in the chunk.
     * @param chunk Which chunk to add to (they are in a list).
     * @param member Member object to add.
     * @param position At what index in the chunk do we add the object (the members are in a list as well).
     */
    void addMember(int chunk, Member member, int position) {
        ensureCapacity(chunk);
        chunks.get(chunk).addMember(member, position);
    }

    /**
     * Add a member to a chunk.
     * @param chunk Which chunk to add to (they are in a list).
     * @param member Member object to add.
     */
    void addMember(int chunk, Member member) {
        ensureCapacity(chunk);
        chunks.get(chunk).addMember(member);
    }
    
    /**
     * Ensures that we have enough chunks.
     * If we already have enough chunks, this does nothing.
     * This is useful if you want to manipulate a chunk that does not exist yet.
     * @param chunk The chunk we want to know exists.
     */
    private void ensureCapacity(int chunk) {
        while(chunk >= chunks.size()) {
            chunks.add(new Chunk());
        }
    }
    
    void debugPrintAllChunkMembers() {
        for(int i=0; i<chunks.size(); i++) {
            chunks.get(i).debugPrintMembers();
        }
    }
    
    void debugPrintChunkMember(int chunk) {
        if(chunk >= chunks.size()) 
        chunks.get(chunk).debugPrintMembers();
    }
    
    void debugPrintChunkNeighbours(int chunk) {
        
    }
    
    void debugPrintAllChunkNeighBours() {
        
    }
}
